﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SCSEngine.Sprite.Implements;
using SCSEngine.Services;

namespace TriUan.TriUanGame.Effect
{
    public class Particle
    {
        protected SCSServices services;

        public Particle(SCSServices services, Sprite particle, Vector2 position, Vector2 velocity, int timeToLive, Color colorOver,
                        float angle, float angular, Vector2 size)
        {
            this.services = services;

            this.particle = new Sprite(particle.SpriteData);
            this.position.X = position.X - this.particle.SpriteData.Data.Texture.Width / 4;
            this.position.Y = position.Y - this.particle.SpriteData.Data.Texture.Height / 4;
            this.origin = new Vector2(particle.SpriteData.Data.Texture.Width, particle.SpriteData.Data.Texture.Height) / 2;//new Vector2(this.Position.X + this.particle.SpriteData.Data.Texture.Width / 4, this.Position.Y + this.particle.SpriteData.Data.Texture.Height / 4);
            this.velocity = velocity;

            this.timeToLive = timeToLive;
            this.ColorOver = colorOver;

            this.Angle = angle;
            this.angular = angular;
            if (size != Vector2.Zero)
                this.Size = size;
        }

        public void UpdateParticle(GameTime gameTime)
        {
            this.Position += velocity;
            this.Angle += angular;
        }

        public void DrawParticle(GameTime gameTime)
        {
            services.SpritePlayer.Draw(particle, this.Position, this.Angle, 1f, this.origin, this.ColorOver, SpriteEffects.None, 1.0f);
        }

        protected void CheckTimeToLive()
        {
        }

        // Fields
        protected Sprite particle;
        protected Vector2 velocity;
        protected int timeToLive;

        protected float angular;
        protected Vector2 position;
        protected Vector2 origin;
        protected float angle;
        protected Color color;
        protected Vector2 size;

        // Properties
        public Sprite Texture
        {
            get { return this.particle; }
            set { this.particle = value; }
        }
        public Vector2 Position
        {
            get { return this.position; }
            set { this.position = value; }
        }
        public Vector2 Velocity
        {
            get { return this.velocity; }
            set { this.velocity = value; }
        }

        public int TimeToLive
        {
            get { return this.timeToLive; }
            set { this.timeToLive = value; }
        }

        public Color ColorOver
        {
            get { return this.color; }
            set { this.color = value; }
        }
        public byte ColorOverA
        {
            get { return this.color.A; }
            set { this.color.A = value; }
        }

        public float Angle
        {
            get { return this.angle; }
            set { this.angle = value; }
        }
        public float Angular
        {
            get { return this.angular; }
            set { this.angular = value; }
        }
        public Vector2 Size
        {
            get { return this.size; }
            set { this.size = value; }
        }
    }
}
